if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SearchStaffPagingCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SearchStaffPagingCount]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO






/*
	version: 1.0
	by: MAC
	date: 2008/03/13
	description:
	
	Initial creation
*/

/*
	vesion: 1.1
	by: MAC
	date: 2008/03/18
	description:

	Added filter for location id
*/

CREATE          PROCEDURE SearchStaffPagingCount
	(
		@LastName VARCHAR(512) = NULL,
		@FirstName VARCHAR(512) = NULL,
		@LocationId  INT = -1
	)
AS
	SET NOCOUNT ON

	-- set a count for the number of matching records
		SELECT COUNT(*) AS VirtualCount
				FROM Staff s
				WHERE (s.LastName LIKE @LastName OR @LastName IS NULL)
				AND (s.FirstName LIKE @FirstName OR @FirstName IS NULL)	
				AND (s.LocationId = @LocationId OR @LocationId = -1)
	
	SET NOCOUNT OFF
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

